package com.wizz.trade.trading.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wizz.trade.trading.dto.FinanceDto;
import com.wizz.trade.trading.dto.page.FinancePageDto;
import com.wizz.trade.trading.entity.Finance;
import com.wizz.trade.trading.mapper.FinanceMapper;
import com.wizz.trade.trading.service.FinanceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.util.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <p>
 * 收付款表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-08-26 04:04:25
 */
@Service
public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> implements FinanceService {

    @Resource
    private FinanceMapper financeMapper;

    @Override
    public void addFinance(FinanceDto financeDto) {
        Finance finance = new Finance();
        BeanUtils.copyProperties(financeDto, finance);
        financeMapper.insert(finance);
    }

    @Override
    public void updateFinance(Finance finance) {
        financeMapper.updateById(finance);
    }

    @Override
    public void deleteFinance(Integer id) {
        financeMapper.deleteById(id);
    }

    @Override
    public void getPage(FinancePageDto financePageDto) {
        LambdaQueryWrapper<Finance> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Objects.nonNull(financePageDto.getMatchstatus()), Finance::getMatchstatus, financePageDto.getMatchstatus())
                        .eq(Objects.nonNull(financePageDto.getLedger()), Finance::getLedger, financePageDto.getLedger())
                        .eq(Objects.nonNull(financePageDto.getOurdept()), Finance::getOurdept, financePageDto.getOurdept())
                        .eq(Objects.nonNull(financePageDto.getCompany()), Finance::getCompany, financePageDto.getOurdept())
                        .likeRight(StringUtils.isNotBlank(financePageDto.getReceiptno()), Finance::getReceiptno, financePageDto.getReceiptno())
                        .likeRight(StringUtils.isNotBlank(financePageDto.getConfirmno()), Finance::getConfirmno, financePageDto.getConfirmno());
        financeMapper.selectPage(PageUtil.initPage(financePageDto), queryWrapper);
    }

}
